/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/12 10:36
  *
  * @file       pd_timer.h
  * @brief      Header file of Timer peripheral driver.
  *
  * @note       This file contains the Timer object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/12     Chris        the first version
  *
  ******************************************************************************
  */

#ifndef JLC_SKY_TIMER_H
#define JLC_SKY_TIMER_H

#include <stm32f407xx.h>
#include "pd_gpio.h"
#include "drivers.h"

typedef struct TimerDef Timer;

struct TimerDef {
    TIM_TypeDef *TIMx;

    uint16_t Prescaler;
    uint32_t Autoreload;
    uint32_t CounterMode;
    uint32_t ClockDivision;
    uint32_t RepetitionCounter;

    void (*init)(Timer *this);

    uint32_t (*get_counter)(Timer *this);
};

extern const struct TimerClass {
    /**
     *
     * @param TIMx       timer instance
     * @param Prescaler  pre-scaler
     * @param Autoreload auto-reload
     * @return
     */
    Timer *(*build)(TIM_TypeDef *TIMx, uint16_t Prescaler, uint32_t Autoreload);
} TimerBuilder;

#endif //JLC_SKY_TIMER_H
